package com.wqiuqiu.gulimall.order.web;


import com.wqiuqiu.common.PageUtils;
import com.wqiuqiu.gulimall.order.entity.OrderEntity;
import com.wqiuqiu.gulimall.order.service.OrderService;
import com.wqiuqiu.gulimall.order.vo.OrderConfirmVo;
import com.wqiuqiu.gulimall.order.vo.OrderSubmitVo;
import com.wqiuqiu.gulimall.order.vo.OrderVo;
import com.wqiuqiu.gulimall.order.vo.SubmitResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.concurrent.ExecutionException;

@Controller
public class OrderWebController {

    @Autowired
    OrderService orderService;

    @GetMapping("/toTrade")
    public String toTrade(Model model, HttpServletRequest request) throws ExecutionException, InterruptedException {
        OrderConfirmVo vo = orderService.toTrade();
        model.addAttribute("data",vo);
        return "confirm";
    }
    @PostMapping("/submitOrder")
    public String toPay(OrderSubmitVo submit, Model model){

        SubmitResponseVo responseVo = orderService.submitOrder(submit);
        if (responseVo.getCode() == 0){
            //成功
            model.addAttribute("submitResponseVo",responseVo);
            return "pay";
        }else {
            //失败
            return "redirect:http://order.gulimall.com/toTrade";
        }
    }

    @GetMapping("/memberOrder.html")
    public String memberOrder(Model model){

        //查出当前用户的全部订单信息
        PageUtils orderEntities = orderService.queryPageMemberOrder(1);
        System.out.println(orderEntities);
        model.addAttribute("memberOrder",orderEntities);
        return "order";
    }

}
